<div class="container">
    <h4>Quản trị quyền hệ thống</h4>
</div>
<div class="container" style="margin-bottom: -1px;" >
    <div style="margin-top: 10px" >
        <ul class="nav nav-tabs nav-collapse">
            <li class="active">
                <a href="<?= $this->baseUrl ?>cp/function.html">Định nghĩa quyền</a>
            </li>
        </ul>
    </div>      
</div> 
<div class="container" style="border: 1px solid #ccc; padding-top: 10px;" >
    <?php foreach ($cpFunctionGroups as $group) { ?>
        <h4> <?= $group->name ?> </h4>
        <table  class="table table-striped table-bordered table-responsive" style="margin: 10px 0px;" >
            <tr class="success" >
                <th class="text-center" style="vertical-align: middle" >Chức năng</th>
                <th class="text-center" style="vertical-align: middle" >Hành động</th>
                <th class="text-center" style="vertical-align: middle; width: 200px;" >
            <div class="btn-group" >
                <button onclick="func.changeCpFunctionGroup(<?= $group->id ?>);" class="btn btn-info">Sửa</button>
                <button onclick="func.removeCpFunctionGroup(<?= $group->id ?>);" class="btn btn-danger">Xóa</button>
            </div>
            </th>    
            </tr>
            <?php $cfunc = false; ?>
            <?php foreach ($cpFunctions as $cpfunction) { ?>
                <?php if ($cpfunction->type == 1 && $cpfunction->groupId == $group->id) { ?>
                    <?php $cfunc = true; ?>
                    <tr>
                        <td style="vertical-align: middle">
                            <p><?= $cpfunction->name; ?></p>
                            <p class="help-block" >(<?= $cpfunction->uri; ?>)</p>
                        </td>
                        <td>
                            <?php foreach ($cpFunctions as $action) { ?>
                                <?php if ($cpfunction->id == $action->parent) { ?>
                                    <p><?= $action->name; ?>
                                        <span class="help-block" >(<?= $action->uri; ?>)</span>
                                    </p>
                                <?php } ?>
                            <?php } ?>
                        </td>
                        <td class="text-center" style="vertical-align: middle" >
                            <div class="btn-group" >
                                <button onclick="func.changeCpFunction(<?= $cpfunction->id ?>);" class="btn btn-info">Sửa</button>
                                <button onclick="func.removeCpFunction(<?= $cpfunction->id ?>);" class="btn btn-danger">Xóa</button>
                            </div>
                        </td>    
                    </tr>
                <?php } ?>
            <?php } ?>
            <?php if (!$cfunc) { ?>
                <tr>
                    <td colspan="3" class="text-center text-danger">Nhóm quyền không có chức năng nào</td>    
                </tr>
            <?php } ?>
        </table>
    <?php } ?>
    <h3>Chức năng chưa được map</h3>
    <table  class="table table-striped table-bordered table-responsive" style="margin: 10px 0px;" >
        <thead>
            <tr class="success" >
                <th class="text-center">Chức năng</th>
                <th class="text-center">Hành động</th>
                <th class="text-center" style="width: 200px;" >Map chức năng</th>    
            </tr>
        </thead>
        <?php foreach ($cpFunctionsMapping as $function => $actions) { ?>
            <tr ref="<?= $function ?>"  >
                <td><?= $function ?></td>
                <td>
                    <?php foreach ($actions as $action) { ?>
                        <p><?= $action ?></p>
                    <?php } ?>
                </td>
                <td class="text-center" style="vertical-align: middle" >
                    <button onclick="func.map('<?= $function ?>')" type="button" class="btn btn-info">Map chức năng</button>
                </td>
            </tr>
        <?php } ?>
    </table>
</div>